<?php

    class Dbase{
	
	private $connection = FALSE;
	private $select_db = FALSE;
	private $result = FALSE;
	private $return_result = array();
	
	function __construct(){
	    
	    
	    
	}
	
	public function connect($db_data){
	    
	    $this->connection = mysql_connect($db_data[0],$db_data[1],$db_data[2]);
	    
	    if (!$this->connection) die (mysql_error());
	    
	    $this->select_db = mysql_selectdb($db_data[3],$this->connection);
	    
	    if (!$this->select_db) die (mysql_error());
	    
	}
	
	public function deconnect(){

	    if (is_resource($this->result)) mysql_free_result($this->result);
	    mysql_close($this->connection);
	    
	}
	
	public function trash(){
	    
	    $this->connection = FALSE;
	    $this->select_db = FALSE;
	    $this->result = FALSE;
	    $this->return_result = array();
	    
	}
	
	public function associate(){
	    
	    $num = mysql_num_rows($this->result);
	    
	    if ($num == 1){
		
		while ($row = mysql_fetch_assoc($this->result)){
		    
		    $this->return_result = $row;
		    
		}
	    
	    }else{
		
		$this->return_result = array();
		
	    }
	    
	}
	
	public function associates(){
	    
	    $num = mysql_num_rows($this->result);
	    
	    if($num > 0){
		
		while ($row = mysql_fetch_assoc($this->result)){
		    
		    $this->return_result[] = $row;
		    
		}
		
	    }else{
		
		$this->return_result = array();
		
	    }
	    
	}
	
	public function select_record($db_data,$query){
	    
	    $this->connect($db_data);
	    
	    $this->result = mysql_query($query);
	    
	    $this->associate();
	    
	    $this->deconnect();
	    
	    $return_data = $this->return_result;
	    
	    $this->trash();
	    
	    return $return_data;
	    
	}
	
	public function select_records($db_data,$query){
	    
	    $this->connect($db_data);
	    
	    $this->result = mysql_query($query);
	    
	    $this->associates();
	    
	    $this->deconnect();
	    
	    $return_data = $this->return_result;
	    
	    $this->trash();
	    
	    return $return_data;
	    
	}
	
	public function insert_record($db_data,$query){
	    
	    $this->connect($db_data);
	    
	    $this->result = mysql_query($query);
	    
	    if ($this->result){
		
		$return_data = mysql_insert_id($this->connection);
		
	    }else{
		
		die(mysql_error());
		
	    }
	    
	    $this->deconnect();
	    
	    $this->trash();
	    
	    return $return_data;
	    
	}
	
	public function update_record($db_data,$query){
	    
	    $this->connect($db_data);
	    
	    $this->result = mysql_query($query);
	    
	    if (!$this->result){
		
		die(mysql_error());
		
	    }
	    
	    $this->trash();
	    
	    $this->deconnect();
	    
	}
	
	public function delete_record($db_data,$query){
	    
	    $this->connect($db_data);
	    
	    $this->result = mysql_query($query);
	    
	    if (!$this->result){
		
		die(mysql_error());
		
	    }
	    
	    $this->trash();
	    
	    $this->deconnect();
	    
	}
	
	function __destruct(){
	    
	    
	    
	}
	
    }

?>